{% extends 'base.html' %}
{% load static %}

{% block title %}{{ page_title }}{% endblock %}

{% block content %}
<div class="container py-4">
    <div class="row">
        <div class="col-12">
            <!-- 页面标题 -->
            <div class="d-flex justify-content-between align-items-center mb-4">
                <div>
                    <h2 class="mb-1">📦 我的兑换记录</h2>
                    <p class="text-muted mb-0">查看您的积分兑换历史</p>
                </div>
                <a href="{% url 'location:reward_mall' %}" class="btn btn-primary">
                    <i class="fas fa-gift me-2"></i>继续兑换
                </a>
            </div>

            <!-- 统计信息 -->
            <div class="row mb-4">
                <div class="col-md-4">
                    <div class="card bg-primary text-white">
                        <div class="card-body text-center py-3">
                            <div class="h4 mb-0">{{ total_redemptions }}</div>
                            <small>总兑换次数</small>
                        </div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="card bg-success text-white">
                        <div class="card-body text-center py-3">
                            <div class="h4 mb-0">{{ total_points_spent }}</div>
                            <small>总消费积分</small>
                        </div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="card bg-info text-white">
                        <div class="card-body text-center py-3">
                            <div class="h4 mb-0">{{ user.points }}</div>
                            <small>当前积分</small>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 兑换记录列表 -->
            <div class="card shadow-sm">
                <div class="card-header bg-light">
                    <h6 class="mb-0">兑换记录</h6>
                </div>
                <div class="card-body p-0">
                    {% if redemptions %}
                    <div class="list-group list-group-flush">
                        {% for redemption in redemptions %}
                        <div class="list-group-item">
                            <div class="row align-items-center">
                                <div class="col-md-6">
                                    <h6 class="mb-1">{{ redemption.reward.name }}</h6>
                                    <div class="d-flex text-muted small mb-2">
                                        <span class="me-3">
                                            <i class="fas fa-coins me-1"></i>{{ redemption.points_used }} 积分
                                        </span>
                                        <span>
                                            <i class="fas fa-clock me-1"></i>{{ redemption.redemption_time|date:"Y-m-d H:i" }}
                                        </span>
                                    </div>
                                    <p class="text-muted small mb-0">{{ redemption.reward.description }}</p>
                                </div>
                                <div class="col-md-4">
                                    <span class="badge
                                        {% if redemption.status == 'completed' %}bg-success
                                        {% elif redemption.status == 'cancelled' %}bg-danger
                                        {% else %}bg-warning{% endif %}">
                                        {{ redemption.get_status_display }}
                                    </span>
                                </div>
                                <div class="col-md-2 text-end">
                                    <a href="{% url 'location:redemption_detail' redemption.id %}"
                                       class="btn btn-sm btn-outline-primary">
                                        查看详情
                                    </a>
                                </div>
                            </div>
                        </div>
                        {% endfor %}
                    </div>
                    {% else %}
                    <div class="text-center py-5">
                        <i class="fas fa-exchange-alt fa-3x text-muted mb-3"></i>
                        <h5 class="text-muted">暂无兑换记录</h5>
                        <p class="text-muted mb-3">快去积分商城兑换心仪的商品吧！</p>
                        <a href="{% url 'location:reward_mall' %}" class="btn btn-primary">
                            <i class="fas fa-gift me-2"></i>前往积分商城
                        </a>
                    </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}